import axios from 'axios'
import Qs from 'qs'
import userUrl from '../../util/url'
import session from '../../util/session'

let url = userUrl + 'login.php'


const login = {
    namespaced: true,
    state: {},
    mutations: {},
    actions: {
        getLogin({ state, commit, dispath }, users) {
            return new Promise((resolve, rejact) => {
                axios({
                    headers: {
                        "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
                    },
                    method: 'post',
                    url,
                    data: Qs.stringify({ name: users.loginName, key: users.loginKey })
                }).then(res=>{
                    console.log(res.data)
                    if(res.data.success){
                        session.save(res.data.data)
                        resolve()
                    }else{
                        alert(res.data.message)
                    }
                })
            })

        }
    }
}
export default login